package com.zbkj.dal.base.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum SharePartyEnums {

    DIRECT_REFERRER("DIRECT_REFERRER", "直接推荐人", SharePayeeTypeEnums.USER),
    INDIRECT_REFERRER("INDIRECT_REFERRER", "间接推荐人", SharePayeeTypeEnums.USER),
    PRODUCT_OWNER("PRODUCT_OWNER", "物主", SharePayeeTypeEnums.USER),
    MEMBER_BIND_MERCHANT("MEMBER_BIND_MERCHANT", "会员所属店铺", SharePayeeTypeEnums.MERCHANT),
    MEMBER_BIND_MERCHANT_MANAGER("MEMBER_BIND_MERCHANT_MANAGER", "店长", SharePayeeTypeEnums.USER),
    SERVICE_MERCHANT("SERVICE_MERCHANT", "服务店铺", SharePayeeTypeEnums.MERCHANT),
    SERVICE_MERCHANT_MANAGER("SERVICE_MERCHANT_MANAGER", "服务店长", SharePayeeTypeEnums.USER),
    SHAN_XIE("SHAN_XIE", "贝贝奢护", SharePayeeTypeEnums.PLATFORM),
    ;

    private final String code;
    private final String desc;
    private final SharePayeeTypeEnums sharePayeeTypeEnums;

    public static Boolean isUser(String code) {
        SharePartyEnums shareParty = getByCode(code);
        return shareParty != null && SharePayeeTypeEnums.USER.equals(shareParty.getSharePayeeTypeEnums());
    }

    public static SharePartyEnums getByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        return Arrays.stream(SharePartyEnums.values()).filter(sharePartyEnums -> StringUtils.equals(code, sharePartyEnums.getCode())).findFirst().orElse(null);
    }
}
